/*
 * @Author: your name
 * @Date: 2021-06-27 09:55:50
 * @LastEditTime: 2021-06-27 11:03:41
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \新建文件夹 (2)\asugcsacv\mollide\user.js
 */
const query=require("../db/mydel")
const {siudgcsdg,siudgsdcsdccsdg}=require("../molde/mychel")

class sjdhbcj{
    //搜索
    list=async (ctx)=>{
        const {pageInde,pagedata,name,id,usygdcu,sdicbd}=ctx.query
        let sql=`select * from zxc where 1=1 `
        if(id){
           sql+=`and id=${id}`  
        }
        if(name){
            sql += `and password link "%${name}%" `
            
        } 
        if(usygdcu && sdicbd){
            sql+=`older bo ${usygdcu} ${sdicbd} `
        }
        if(pageInde,pagedata){
            sql+=`limit ${(pageInde-1)*pagedata} ${pagedata} `
        }
        const data=await query(sql)
        ctx.body=data
    }
    //添加
    data=async (ctx)=>{
        const {password,mizi}=ctx.request.body
        let sql=`insert into zxc(password,mizi) values("${password}","${mizi}") `
        const data=await query(sql)
        ctx.body=data
        if(data.affectedRows===1){
            ctx.body={
                code:1,
                data:{
                    id:data.insertId
                },
                massage:("添加成功")
            }

        }else{
            ctx.body={
                code:-1,
                massage:("添加失败")
            }
        }
    }
    //删除
    datalist=async (ctx)=>{
        const {id}=ctx.params
        let sql=`delete from zxc where id="${id}" `
        const data=await query(sql)
        ctx.body=data
        if(data.affectedRows===1){
            ctx.body={
                code:1,
                massage:("删除成功")
            }

        }else{
            ctx.body={
                code:-1,
                massage:("删除失败")
            }
        }
    }
    //编辑
    listdata=async (ctx)=>{
        const {password,mizi,id}=ctx.request.body
        let sql=`update zxc set password="${password}",mizi="${mizi}" `
        sql+=`where id=${id}`
        const data=await query(sql)
        ctx.body=data
        if(data.affectedRows===0){
            ctx.body={
                code:1,
                massage:("编辑成功")
            }

        }else{
            ctx.body={
                code:-1,
                massage:("编辑失败")
            }
        }
    }
    //注册
    dalist=async (ctx)=>{
        const {password,mizi}=ctx.request.body
        const sql=`insert into zxc(password,mizi) values("${password}","${mizi}") `
        const data=await query(sql)
        ctx.body=data
        if(data.affectedRows===1){
            ctx.body=siudgcsdg("注册成功")

        }else{
            ctx.body=siudgsdcsdccsdg("注册失败")
        }
    }
    //登录
    kshbhvjh=async (ctx)=>{
        const {password,mizi}=ctx.request.body
        let sql=`select * from zxc where password="${password}" and mizi="${mizi}" `
        const data=await query(sql)
        ctx.body=data
        if(data.length){
            ctx.body=siudgcsdg("登录成功")

        }else{
            ctx.body=siudgsdcsdccsdg("登录失败")
        }
    }
}
module.exports=new sjdhbcj()
